<?php

class Controller_Advertiser extends Controller_Abstract
{
	function actionShow()
	{
	}	
	
	function actionIndex()
	{
		if (isset($_SESSION['infos'])) {
			$this->_view['infos'] = $_SESSION['infos'];
			unset($_SESSION['infos']);
		}
		$advertiserModel = new Advertiser();
		$this->_view['advertisers'] = $advertiserModel->getAllAdvertisers();
	}
	
	function actionAdd()
	{
		if ($this->_context->isPOST()) {
			$advertiserModel = new Advertiser();
			if ($advertiserModel->addNewAdvertisers($_POST['advertisers'])) {
				$infos = array();
				$infos[] = Util::getMessage(12001);
				$this->_view['infos'] = $infos;
			}
		}
	}
	
	function actionEdit()
	{
		if (!empty($this->_context->id)) {
			$id = $this->_context->id;
		}
		$advertiserModel = new Advertiser();
		if ($this->_context->isPOST()) {
			if (!empty($this->_context->id)) {
				if ($advertiserModel->updateAdvertiser($id, $this->_context->name)) {
					$infos = array();
					$infos[] = Util::getMessage(12002);
					$_SESSION['infos'] = $infos;
					return $this->_redirect(url('advertiser/index'));
				}
			}
		} else {
			if (($advertiser = $advertiserModel->getAdvertiser($id)) !== false) {
				$this->_view['advertiser'] = $advertiser;
			}
		}
		
	}
	
	function actionDelete()
	{
		if (!empty($this->_context->id)) {
			$advertiserModel = new Advertiser();
			if ($advertiserModel->deleteAdvertiser($this->_context->id)) {
				$infos = array();
				$infos[] = Util::getMessage(12003);
				$_SESSION['infos'] = $infos;
				return $this->_redirect(url('advertiser/index'));
			}
		}
	}
}
?>